//变量缓存器，方便我们在不同的类中访问和修改变量
import Common from './Common.js'
import Instance from './Instance.js'

export default class extends Instance{
  constructor() {
    super()
    this.map = new Map()
  }
  get(key) {
    this.errorCheck(key)
    return this.map.get(key)
  }
  put(key, value) {
    this.errorCheck(key)
    if (typeof value === 'function') {
      value = new value()
    }
    this.map.set(key, value)
    return this
  }
  destroy() {
    for (let value of this.map.values()) {
      value = null
    }
    this.map.clear()
  }
  errorCheck(key) {
    if (!key) Common.Error('key')
  }
}
